package com.time.timespace.controller;

import com.time.timespace.commons.dto.ResponseEntity;
import com.time.timespace.domain.entity.Comments;
import com.time.timespace.service.CommentsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "评论管理")
@Slf4j
@RequestMapping("/comments")
public class CommentsController {

    private final CommentsService commentsService;

    public CommentsController(CommentsService commentsService) {
        this.commentsService = commentsService;
    }

    @Operation(description = "查询所有评论")
    @GetMapping("/select-all")
    public ResponseEntity<List<Comments>> selectAll() {
        List<Comments> commentsList = commentsService.selectAll();
        return ResponseEntity.success(commentsList);
    }

    @Operation(description = "保存评论")
    @PostMapping("/save")
    public ResponseEntity<Comments> saveComments(@RequestBody Comments comments) {
        return ResponseEntity.success(commentsService.saveComments(comments));
    }

    @Operation(description = "删除评论")
    @GetMapping("/delete/{id}")
    public void deleteById(@PathVariable Long id) {
        commentsService.deleteById(id);
    }
}
